import {Hono} from "hono";
import {memoizedKplTopHys, memoizedKplTopPlates} from "@/backend/services/kpl-service";


export const kplRouter = new Hono()
    .get('/top-plates/:num', async (c) => {
        const {num} = c.req.param();
        const cached = await memoizedKplTopPlates(parseInt(num));
        const data = structuredClone(cached)
        data.list.map((d: any) => {
            d[6] = parseFloat((d[6] / 100000000).toFixed(2));
        })

        return c.json({data});
    })
    .get('/top-hys/:num', async (c) => {
        const {num} = c.req.param();
        const cached = await memoizedKplTopHys(parseInt(num));
        const data = structuredClone(cached)
        data.list.map((d: any) => {
            d[6] = parseFloat((d[6] / 100000000).toFixed(2));
        })

        return c.json({data});
    })